package com.person.leetcode.editor.cn;

/**
  * 141.环形链表
  * 2022-07-14 17:19:54
**/
public class Sequence_0141_LinkedListCycle {
    public static void main(String[] args) {
        Solution solution = new Sequence_0141_LinkedListCycle().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        if (head == null){
            return false;
        }else{
            ListNode pos = head;
            ListNode pos2 = pos.next;
            while(pos2 != null && pos2.next != null){
                if (pos == pos2){
                    return true;
                }else {
                    pos = pos.next;
                    pos2 = pos2.next.next;
                }
            }
            return false;
        }
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}